import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/Home',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import( '../views/About.vue')
  },
  {
    path: '/',
    name: 'regist',
    component: () => import( '../views/personal/regist')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '../views/personal/login')
  },
  
  {
    path: '/mail',
    name: 'mail',
    redirect:{name:'center'},
    component: () => import( '../views/personal/mail'),
    children:[
      {
        path: 'com',
        name: 'com',
        component: () => import( '../views/personal/com')
      },
      {
        path: 'integral',
        name: 'integral',
        component: () => import( '../views/personal/integral')
      },
      {
        path: 'center',
        name: 'center',
        component: () => import( '../views/personal/center')
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next)=>{
  if(!localStorage.getItem('user')){
    if(to.path !== '/login'){
      next('/login')
    }
  }
  next()
})

export default router
